#!/usr/bin/env python

""" Image tools
    - Zoom in
    - Zoom out
    - Select
    - Gray
    - Binary
    - Rotate

    Image hash values
    - Average Hash
    - Dynamic Hash
    - Perceptual Hash

    Store the adjust parameters into a JSON file
"""

import io
import sys

import imagehash
from PIL import Image

# https://zh.wikipedia.org/wiki/%E5%A4%A7%E6%B4%A5%E7%AE%97%E6%B3%95#JavaScript.E5.AE.9E.E7.8E.B0
def otsu(histogram):
    pass



def to_binary(img, threshold):
    bitmap = [0 if i < threshold else 1 for i in range(256)]
    return img.convert('L').point(bitmap, '1')


def main():
    pass


if __name__ == '__main__':
    # raw = Image.open(io.BytesIO(b''))
    raw = Image.open(sys.argv[1])
    img = to_binary(raw, 128)
    img.show()
    raw.close()
